package com.wondream.myframework.juc;

import org.junit.Test;

/**
 * @author wondream
 * @version 1.0
 * @create 2022/5/22 3:35 PM
 */
public class JUC03ReorderingTest {

    static int x = 0, y = 0, a = 0, b = 0;

    @Test
    public void run() throws InterruptedException {
        for (int i = 0; i < 100; i++) {
            x = y = a = b = 0;
            Thread one = new Thread(){
                public void run(){
                    a = 1;
                    x = b;
                }
            };
            Thread two = new Thread(){
                public void run(){
                    b = 1;
                    y = a;
                }
            };
            one.start();
            two.start();
            one.join();
            two.join();
            System.out.println(x+" "+y);
        }
    }
}
